package com.bridgeintelligent.tag.bulkload.service.es;

import com.bridgeintelligent.tag.bulkload.api.fileload.FileLoadModel;
import com.bridgeintelligent.tag.bulkload.service.es.query.IQueryCallback;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.reindex.BulkByScrollResponse;
import org.elasticsearch.script.Script;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.Lock;

/**
 * Created by JackCheung on 2019/9/7 11:09 PM.
 */
interface IESHelper {

    int ES_SLICE_MAX = 10;

    /**
     * 创建索引
     *
     * @param indexName
     */
    void createIndex(String indexName, String indexType);

    /**
     * 获取索引下的mapping字段集合
     * @param indexName
     * @return
     */
    Set<String> getIndexMapping(String indexName);

    /**
     * 设置索引字段映射
     *
     * @param indexName
     * @param map
     */
    void updateIndexMapping(String indexName, String indexType, Map<String, String> map);

    /**
     * 删除索引
     *
     * @param indexName
     */
    void delIndex(String indexName);

    /**
     * 新增文档
     *
     * @param indexName
     * @param documentId
     * @param map
     */
    void insert(String indexName, String indexType, String documentId, Map<String, Object> map);

    /**
     * 更新文档
     *
     * @param indexName
     * @param documentId
     * @param map
     */
    void update(String indexName, String indexType, String documentId, Map<String, Object> map);
    /**
     * 更新文档
     *
     * @param indexName
     * @param
     * @param
     */
    BulkByScrollResponse updateByQuery(String indexName,QueryBuilder queryBuilder, Script script);

    /**
     * 批量新增文档
     *
     * @param indexName
     * @param map
     */
    void bulkInsert(String indexName, String indexType, Map<String, Map<String, Object>> map);

    /**
     * 批量更新文档
     *
     * @param indexName
     * @param map
     */
    void bulkUpdate(String indexName, String indexType, Map<String, Map<String, Object>> map);

    /**
     * 批量删除文档
     *
     * @param indexName
     * @param map
     */
    void bulkUpdateWithDel(String indexName, String indexType, Map<String, String> map);

    /**
     * 搜索文档
     *
     * @param indexName
     * @param docId
     */
    void searchDoc(String indexName, String indexType, String docId);

    void scrollSearch(String indexName, FileLoadModel fileLoadModel, IQueryCallback iQueryCallback);

    void newScrollSearch(String indexName, FileLoadModel fileLoadModel, IQueryCallback iQueryCallback, int sliceId,
                      Lock lock, CountDownLatch countDownLatch);

    Map<String,String> multiSearchDoc(List<String> ids, String indexName, String[] includes);

    RestHighLevelClient getClient();
}
